package com.mifengs.mall.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mifengs.mall.R;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.RedPacket;
import com.mifengs.mall.loader.GlideImageLoader;
import com.mifengs.mall.util.ImageLoadUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by lihaoqi on 2018/1/26.
 */

public class RedPacketAdapter extends BaseQuickAdapter<RedPacket,BaseViewHolder> {

    private Context mContext;
    private int mType;


    public RedPacketAdapter(@Nullable List<RedPacket> data, Context mContxt,int type) {
        super(R.layout.item_red_packet, data);
        this.mContext = mContxt;
        this.mType = type;
    }


    @Override
    protected void convert(BaseViewHolder helper, RedPacket item) {

        helper.setText(R.id.tv_amount,item.getCommissionAmount()+"");
        helper.setText(R.id.tv_red_type,item.getRedEnvelopTypeText());
        helper.setText(R.id.tv_red_detail,item.getCommissionTypeText());


        //ImageLoadUtil.displayImage(mContext,item.getIconUrl(), (ImageView) helper.getView(R.id.iv_img));


        //红包图片设置
        if(mType==3){
            helper.setImageResource(R.id.iv_img,R.drawable.ic_red_lose);
        }else if(mType==2){//抽奖红包
            helper.setImageResource(R.id.iv_img,R.drawable.ic_item_red_bg);
        }else if(mType==0){
            helper.setImageResource(R.id.iv_img,R.drawable.ic_red_clearing);
        }


        int reviceStatus = item.getReceiveStatus();
        int redEnvelopType = item.getRedEnvelopType();
        if(reviceStatus==0){ //未领取
            if(redEnvelopType == 0||redEnvelopType==2){
                long time = item.getModifyDate();
                Date modifyDate = new Date(time);
                SimpleDateFormat modifyFormat = new SimpleDateFormat("yyyy-MM-dd");
                String modifyTime = modifyFormat.format(modifyDate);
                helper.setText(R.id.tv_time,"结算时间: "+modifyTime);
                helper.setText(R.id.tv_status_time,time+","+"结算时间");
            }else if(redEnvelopType == 3){
                long time = item.getCreateDate();
                Date createDate = new Date(time);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String creatTime = dateFormat.format(createDate);
                helper.setText(R.id.tv_time,"发放时间: "+creatTime);
                helper.setText(R.id.tv_status_time,time+","+"发放时间");
            }else if(redEnvelopType ==1){
                long time = item.getDeadLine();
                Date deadLinedate = new Date(time);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String deadTime = dateFormat.format(deadLinedate);
                helper.setText(R.id.tv_time,"过期时间: "+deadTime);
                helper.setText(R.id.tv_status_time,time+","+"过期时间");
            }
            helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_red_rev);
            helper.setText(R.id.tv_rev_status,"待领取");
            helper.addOnClickListener(R.id.iv_rev_status);
        }else if(reviceStatus == -1){ // 未结算
            helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_bt_clearing);
            helper.setText(R.id.tv_rev_status,"待结算");


//            long time = item.getCreateDate();
//            Date createDate = new Date(time);
//            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//            String creatTime = dateFormat.format(createDate);
//            helper.setText(R.id.tv_time,"发放时间: "+creatTime);
//            helper.setText(R.id.tv_status_time,time+","+"发放时间");
            if(redEnvelopType==0){
                long time = item.getCreateDate();
                Date createDate = new Date(time);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String creatTime = dateFormat.format(createDate);
                helper.setText(R.id.tv_time,"发放时间: "+creatTime);
                helper.setText(R.id.tv_status_time,time+","+"发放时间");
            }else{
                long time = item.getDeadLine();
                Date deadLinedate = new Date(time);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String deadTime = dateFormat.format(deadLinedate);
                helper.setText(R.id.tv_time,"过期时间: "+deadTime);
                helper.setText(R.id.tv_status_time,time+","+"过期时间");//不想在detail 再去判断一次 直接传过去
            }
        }else if(reviceStatus == 1){  //已领取
            helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_red_yirev);
            helper.setText(R.id.tv_rev_status,"已领取");
            long modifyTime = item.getModifyDate();
            Date modifyDate = new Date(modifyTime);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String modiftTime = dateFormat.format(modifyDate);
            helper.setText(R.id.tv_time,"领取时间: "+modiftTime);
            helper.setText(R.id.tv_status_time,modifyTime+","+"领取时间");
        }

        if(mType==3){
            helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_bt_lose);
            helper.setText(R.id.tv_rev_status,"已失效");
            if(reviceStatus== 2){ //已经失效
                long modifyTime = item.getModifyDate();
                Date modifyDate = new Date(modifyTime);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String modiftTime = dateFormat.format(modifyDate);
                helper.setText(R.id.tv_time,"失效时间: "+modiftTime);
                helper.setText(R.id.tv_status_time,modifyTime+","+"失效时间");
            }else { //过期
                helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_bt_lose);
                helper.setText(R.id.tv_rev_status,"已失效");
                long time = item.getDeadLine();
                Date deadLinedate = new Date(time);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String deadTime = dateFormat.format(deadLinedate);
                helper.setText(R.id.tv_time,"过期时间: "+deadTime);
                helper.setText(R.id.tv_status_time,time+","+"过期时间");
            }
        }




  /*      if(mType==0){
            helper.addOnClickListener(R.id.iv_rev_status);
            helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_red_rev);
        }else{
            if(item.getReceiveStatus()==0){
                helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_guoqi);
            }else{
                helper.setImageResource(R.id.iv_rev_status,R.drawable.ic_red_yirev);
            }

        }*/

    }


}
